In this tutorial you learn how to create user interfaces that respond to the changes of the device screen resolution. A user interface with a dynamic layout looks good and is easy to use regardless of the device and its screen resolution.
This video shows the result of the tutorial.
This tutorial assumes you understand the basics of working with Kanzi Studio. The best entry points for getting familiar with Kanzi Studio are:
The <KanziWorkspace>/Tutorials/Dynamic layout/Completed directory contains the completed project of this tutorial.
The starting point of this tutorial is the Dynamic layout.kzproj Kanzi Studio project file stored in the <KanziWorkspace>/Tutorials/Dynamic layout/Assets directory.
User interfaces with dynamic layout respond to changes in device screen orientation and resolution. Grid Layout nodes form the base of dynamic layouts. To make your Kanzi application layout dynamic, you have to place inside Grid Layout nodes all content for which you want that it responds to the changes in the screen resolution. Then you set up the Grid Layout nodes so that they position and distribute the content the way you want.
The project contains the two Grid Layout 2D nodes you need to complete this tutorial:
In this section you make the layout of the user interface (Player and Controls Grid Layout 2D nodes) respond to the changes of the device screen orientation and resolution.
In this project the RootPage fills the entire device screen. Because the size of the RootPage node changes with the device resolution, use its height and width as a base for setting the dimensions of nodes in your user interface.
To make the layout of the user interface responsive:
CLAMP(400, 1200, {@../Node.ActualHeight} - 300)Click Save.
Clamp()
binding function to constrain the height of the Player node:CLAMP(500, {@../Node.ActualWidth}, {@../Node.ActualWidth} - 300)Click Save.
Clamp()
binding function to constrain the width of the Player node:{@../Node.Height}Click Save.
CLAMP(500, 1300, {@../Node.Width} - 300)Click Save.
Clamp()
binding function to constrain the width of the Controls node:In this section you make the content of the Controls Grid Layout 2D node respond to the changes of the device screen orientation and resolution. That way the controls in the user interface change with changes of the screen resolution.
To make the content in the user interface responsive:
CLAMP(10, 60, {@../Node.Height} / 20)Click Save.
Clamp()
binding function to constrain the height of the Song list node:CLAMP(10, 60, {@../Node.Width} / 20)Click Save.
CLAMP(50, 120, {@../../../Node.ActualHeight} / 5)
Click Save.
This binding sets the height of the Play Image node based on the height of the RootPage node. With this binding the size of the Play node changes differently from the other nodes in the Controls node.
CLAMP(50, 120, {@../../../Node.ActualWidth} / 5)Click Save.
In this tutorial you learned how to create a user interface the size of which responds to the changes of the device screen resolution. This project contains Text Block nodes the text of which stays the same regardless of the changes in the device screen resolution. You can use the approach you learned in this tutorial to make the size of the text in the Text Block nodes respond to the changes of the device screen resolution.
You can also:
To learn more about how the Grid Layout nodes work, see Using the Grid Layout nodes.
To learn more about using bindings, see Using bindings and Bindings expressions reference.